//
//  BaseDatabase.m
//  yuikemall
//
//  Created by Gang.Wang on 12-5-18.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "BaseDatabase.h"
#import "EntityManager.h"
#import "mcf.h"

@interface BaseDatabase ()
{
        
}


@end


@implementation BaseDatabase

@synthesize entityManager;
@synthesize bInited;

@synthesize version;
@synthesize name;

@synthesize date;
@synthesize discription;

-(void) dealloc
{    
    YRelease(entityManager)
    
    YRelease(version)
    YRelease(name)
    
    YRelease(date)
    YRelease(discription)
    
    [super dealloc];
}



#pragma mark - Public Method
- (id) initWithDataBasePath:(NSString *) databasePath
{
    self = [super init];
    if (self) 
    {
        if ([NSString isNilOrEmpty:databasePath]) 
        {
            return nil;
        }
        
        if (![YFile fileExistsAtPath:databasePath]) 
        {
           // return nil;
        }
        
        EntityManager * temp_entityManager = [[EntityManager alloc] initWithDataPath:databasePath];
        
        self.entityManager = temp_entityManager;
        YRelease(temp_entityManager);
        
        
        
        [self privateInit];
        
    }
    return self;
}


- (NSArray *) allRecords:(NSString *) className
{
    if ([NSString isNilOrEmpty:className]) 
    {
        return nil;
    }
    
    return [self.entityManager find:className];
}

#pragma mark - Private Method
- (BOOL) privateInit
{
    if (self.bInited) 
    {
        return FALSE;
    }
    
    
    self.bInited = TRUE;
    return TRUE;
}

@end
